package com.akupilih.app;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.akupilih.app.adapter.CustomAdapter;
import com.akupilih.app.entity.E_Organisasi;
import com.akupilih.app.entity.E_Pekerjaan;
import com.akupilih.app.model.DBClass;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class OrganisasiFragment extends Fragment {

	private FragmentActivity myContext;
	ListView listView;
	List<E_Organisasi> dataList;
	ArrayList<HashMap<String, Object>> postitem;
	public static final String KEY_HEAD = "title";
	public static final String KEY_BODY = "jabatan";
	public static final String KEY_FOOT = "tahun";

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		View rootView = inflater.inflate(R.layout.fragment_pasangan, container,
				false);
		listView = (ListView) rootView.findViewById(R.id.listview);
		DBClass db = new DBClass(getActivity());
		String id = getArguments().getString("id");

		dataList = db.selectOrganisasi(id);
		setList(dataList);
		return rootView;
	}

	private void setList(List<E_Organisasi> dataList2) {
		postitem = new ArrayList<HashMap<String, Object>>();
		if (dataList2 != null) {
			for (E_Organisasi e : dataList2) {
				HashMap<String, Object> map = new HashMap<String, Object>();
				map.put(KEY_HEAD, e.getRingkasan());
				map.put(KEY_BODY, e.getJabatan());
				map.put(KEY_FOOT, e.getTgl_mulai() + " - " + e.getTgl_selesai());
				postitem.add(map);
			}
			ListAdapter adapter = new CustomAdapter(myContext, postitem,
					R.layout.row_organisasi, new String[] { KEY_HEAD, KEY_BODY,
							KEY_FOOT }, new int[] { R.id.head, R.id.body,
							R.id.foot });
			listView.setAdapter(adapter);
			listView.setDivider(null);

		}

	}

	@Override
	public void onAttach(Activity activity) {
		// TODO Auto-generated method stub
		super.onAttach(activity);
		myContext = (FragmentActivity) activity;

	}

}
